#ifndef FS_DB_H
#define FS_DB_H

#include "sqlite3.h"
#include <stdbool.h>
#include "config.h"

// 数据库初始化
sqlite3 *fs_db_init();
void fs_db_close(sqlite3 *db);

// 用户管理
int fs_create_user(sqlite3 *db, const char *username, const char *email, const char *password_hash);
int fs_delete_user(sqlite3 *db, const char *username);
int fs_get_user_id(sqlite3 *db, const char *username);
bool fs_user_exists(sqlite3 *db, const char *username);

// 目录管理
int fs_create_directory(sqlite3 *db, const char *path, const char *name, int owner_id);
int fs_get_directory_id(sqlite3 *db, const char *path);
int fs_get_parent_directory_id(sqlite3 *db, const char *path);
bool fs_directory_exists(sqlite3 *db, const char *path);

// 文件操作
int fs_add_file(sqlite3 *db, const char *path, const char *name, int owner_id,
                long size, bool is_public, int parent_id);
int fs_update_file(sqlite3 *db, const char *path, long new_size);
int fs_delete_file(sqlite3 *db, const char *path);
int fs_move_file(sqlite3 *db, const char *old_path, const char *new_path);
int fs_copy_file(sqlite3 *db, const char *src_path, const char *dest_path);
int fs_mark_file_public(sqlite3 *db, const char *path, bool is_public);

// 文件检索
void fs_list_user_files(sqlite3 *db, int user_id);
void fs_list_directory(sqlite3 *db, const char *dir_path);
void fs_search_files(sqlite3 *db, const char *username, const char *query);

// 数据库维护
int fs_scan_user_directory(sqlite3 *db, const char *username);
int fs_rebuild_index(sqlite3 *db);
int fs_sync_file(sqlite3 *db, const char *file_path, int owner_id);

// 回收站管理
int fs_move_to_recycle_bin(sqlite3 *db, const char *file_path);
int fs_restore_from_recycle_bin(sqlite3 *db, int recycle_id);
void fs_empty_recycle_bin(sqlite3 *db);

#endif // FS_DB_H